class Solution(object):
    def findMaxLength(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        prefix = {0: -1}
        max_len = 0
        if not nums[0]:
            nums[0] = -1
        for i in range(1, len(nums)):
            if nums[i]:
                nums[i] = nums[i - 1] + 1
            else:
                nums[i] = nums[i - 1] - 1
        for i in range(len(nums)):
            if nums[i] in prefix:
                max_len = max(i - prefix[nums[i]], max_len)
            else:
                prefix[nums[i]] = i
        return max_len




data = Solution()
nums = [0, 1]
